<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>创建一个HTTP RPC Server</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.yar-server.html">« Yar_Server</a></li>
      <li style="float: right;"><a href="yar-server.handle.html">Yar_Server::handle »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.yar-server.html">Yar_Server</a></li>
    <li>创建一个HTTP RPC Server</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="yar-server.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yar_Server::__construct</h1>
  <p class="verinfo">(PECL yar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Yar_Server::__construct</span> &mdash; <span class="dc-title">创建一个HTTP RPC Server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yar-server.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>Yar_Server::__construct</strong></span>(<span class="methodparam"><span class="type">Object</span> <code class="parameter">$obj</code></span>)</div>

  <p class="para rdfs-comment">
   创建一个Yar的HTTP RPC服务，参数 $obj 对象的所有公开方法都会被注册为服务函数，
   可以被RPC调用。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yar-server.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">obj</code></dt>

    <dd>

     <p class="para">
      一个对象实例, 这个对象的所有公开方法都会被注册为服务函数.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-yar-server.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个<span class="classname"><a href="class.yar-server.html" class="classname">Yar_Server</a></span>的实例。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yar-server.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5355">
   <p><strong>示例 #1 <span class="function"><strong>Yar_Server::__construct()</strong></span>示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">API&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;the&nbsp;doc&nbsp;info&nbsp;will&nbsp;be&nbsp;generated&nbsp;automatically&nbsp;into&nbsp;service&nbsp;info&nbsp;page.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@params&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">some_method</span><span style="color: #007700">(</span><span style="color: #0000BB">$parameter</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$option&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;function&nbsp;</span><span style="color: #0000BB">client_can_not_see</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$service&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yar_Server</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">API</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$service</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-yar-server.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="yar-server.handle.html" class="methodname" rel="rdfs-seeAlso">Yar_Server::handle()</a> - 启动HTTP RPC Server</span></li>
  </ul>
 </div>


</div></div></div></body></html>